import datetime as datetime
import pymongo
import sys
sys.path.append('C:/Project/Python3')
sys.path.append('D:/Project/Python3')
import Core.MongoDB as MongoDB
import Core.Gadget as Gadget
import Core.IO as IO
import DataProcess
import Core.WindFunctions as Wind

from Core.Config import *
config = Config()
database = config.DataBase()
realtime = config.RealTime()


# ---Current Time---
endDateTime = datetime.datetime.now()
if endDateTime.time() < datetime.time(15,0,0):
    endDateTime += datetime.timedelta(days=-1)
endDateTime = Gadget.ToDate(endDateTime)

# ---Start Wind API---
Wind.w.start()

# ---Automatic update Fundamentals ---
# DataProcess.Automatic_Download_Fundamentals(database, endDateTime)

# ---Update Instrument List---
DataProcess.Request_Write_Stock_List(database)
# DataProcess.Request_Write_Index_List()

# ---Update Futures---
DataProcess.Request_Write_Future_List(database=database, realtime=realtime)

# ---更新共募集金信息,和下市信息---
#Wind.Request_Write_MutualFund_List(database, endDateTime, forceToUpdate = False)

# ---更新期权列表---
DataProcess.Request_Write_Option_List(database=database, realtime=realtime)


DataProcess.Automatic_Download_DailyQuote(database, endDateTime, instrumentType="Index")
DataProcess.Automatic_Download_DailyQuote(database, endDateTime, instrumentType="Stock")
#DataProcess.Automatic_Download_DailyQuote(database, endDateTime, instrumentType="Future")
#DataProcess.Automatic_Request_Write_Daily_Quote(database, endDateTime, instrumentType="Option")
#DataProcess.Automatic_Request_Write_Daily_Quote(database, endDateTime, instrumentType="Bond")
#DataProcess.Automatic_Request_Write_Daily_Quote(database, endDateTime, instrumentType="MutualFund")